﻿namespace Onetube.Providers
{
    using System;

    public class YouTubeUri
    {
        internal string url;

        public bool IsValid
        {
            get
            {
                if (this.url == null || this.Itag <= 0)
                {
                    return false;
                }
                return this.Type != null;
            }
        }

        public int Itag
        {
            get;
            set;
        }

        public VideoQuality Quality
        {
            get
            {
                int itag = this.Itag;
                if (itag > 22)
                {
                    switch (itag)
                    {
                        case 36:
                        {
                            return VideoQuality.Low;
                        }
                        case 37:
                        {
                            return VideoQuality.FullHD;
                        }
                        default:
                        {
                            switch (itag)
                            {
                                case 82:
                                {
                                    return VideoQuality.Medium;
                                }
                                case 83:
                                {
                                    return VideoQuality.Low;
                                }
                                case 84:
                                case 85:
                                {
                                    return VideoQuality.High;
                                }
                            }
                            break;
                        }
                    }
                }
                else
                {
                    if (itag == 18)
                    {
                        return VideoQuality.Medium;
                    }
                    if (itag == 22)
                    {
                        return VideoQuality.High;
                    }
                }
                return VideoQuality.None;
            }
        }

        public string Type
        {
            get;
            set;
        }

        public Uri Uri
        {
            get
            {
                return new Uri(this.url, UriKind.Absolute);
            }
        }

        public YouTubeUri()
        {
        }
    }
}

